package com.bike.controller.information;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bike.controller.BaseController;
import com.bike.entity.HhAdvice;
import com.bike.entity.HhOrder;
import com.bike.entity.SysRole;
import com.bike.entity.SysUser;
import com.bike.util.Constant;
import com.bike.util.PageData;
import com.bike.util.TimeManager;
import com.bike.service.impl.HhAdviceServiceImpl;
import com.bike.service.impl.HhAgentServiceImpl;
import com.bike.service.impl.HhOrderServiceImpl;

 
@Controller
@RequestMapping(value="/home")
public class HhHomeController extends BaseController {
	
		@Autowired
		private HhAdviceServiceImpl  hhAdviceService;
		@Autowired
		private HhOrderServiceImpl  hhOrderServiceImpl;
		@Autowired
		private HhAgentServiceImpl  hhAgentServiceImpl;
	
		/**
		 * 跳转到首页
		 */
		@RequestMapping("tohome")
		public String toList(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			
			int startTime=TimeManager.dateTimeMin(pd.getString("startTime"));
			int endTime=TimeManager.dateTimeMax(pd.getString("endTime"));
			
			if(startTime==0){
				startTime=TimeManager.currentdayTime();
			}
			if(endTime!=0){
				pd.put("endDate", endTime);
				model.addAttribute("endTime",pd.getString("endTime"));
			}
			pd.put("startDate", startTime);
			model.addAttribute("startTime",pd.getString("startTime"));
			SysRole role= (SysRole) request.getSession().getAttribute("role");
			SysUser user= (SysUser) request.getSession().getAttribute("user");
			String resultStr="/information/home/home";
			
			if(role.getRoleCode().equals(Constant.agentRole)){
				resultStr="/information/home/agent_home";
				model.addAttribute("agent",hhAgentServiceImpl.selectByHhAgentId(user.getAgentId()));
				pd.put("agentId", user.getAgentId());
			}
			
			PageData result=hhOrderServiceImpl.selectCountForHome(pd);
			model.addAttribute("pd",result);
			
			return resultStr;
		}
		/**
		 * 跳转到代理商明细列表
		 */
		@RequestMapping("toAgentRecordList")
		public String toAgentRecordList(HttpServletRequest request,Model model){
			PageData pd=PageData.getPageDataByPage(request);
			
			return "/information/home/agent_record";
		}
		
		 
}
